import { defineConfig,loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'

// element UI
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'


// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
  const env = loadEnv(mode, process.cwd(), '')
  return{
    base: './',
    resolve: {
      alias: {
        '@': '/src',
      },
    },
    server: {
      host: true,
      open: false,
      port: 5173,
      cors: true,
      proxy: {
        '/api': {
          target: env.VITE_BASE_URL,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, ''),
        },
      },
    },
    plugins: [
        vue(),
      //配置插件
      AutoImport({
        resolvers: [ElementPlusResolver()],
        imports:['vue','vue-router']
      }),
      Components({
        resolvers: [ElementPlusResolver()],
      }),
    ],
  }

})




/*
export default ({ mode }: ConfigEnv): UserConfig => {
  const env = loadEnv(mode, process.cwd());
  return {
    base: './',
    resolve: {
      alias: {
        '@': '/src',
      },
    },
    server: {
      host: true,
      open: false,
      port: 5173,
      cors: true,
      proxy: {
        '/api': {
          target: env.VITE_BASE_URL,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, ''),
        },
      },
    },
    plugins: [uni(), vueJsx({})],
  };
};*/
